home *** CD-ROM | disk | FTP | other *** search
/ X User Tools / X User Tools (O'Reilly and Associates)(1994).ISO / sources / libxpm / libxpm34.gz / libxpm34 / xpm-3.4 / lib / xpmP.h < prev    next >
C/C++ Source or Header  |  1994-03-14  |  8KB  |  259 lines

  1. /* Copyright 1989-94 GROUPE BULL -- See license conditions in file COPYRIGHT */
  2. /*****************************************************************************\
  3. * xpmP.h:                                                                     *
  4. *                                                                             *
  5. *  XPM library                                                                *
  6. *  Private Include file                                                       *
  7. *                                                                             *
  8. *  Developed by Arnaud Le Hors                                                *
  9. \*****************************************************************************/
  10.  
  11. #ifndef XPMP_h
  12. #define XPMP_h
  13.  
  14. /*
  15.  * lets try to solve include files
  16.  */
  17. #ifdef VMS
  18.  
  19. #include "sys$library:stdio.h"
  20. #include "sys$library:string.h"
  21.  
  22. #else  /* VMS */
  23.  
  24. #include <stdio.h>
  25. /* stdio.h doesn't declare popen on a Sequent DYNIX OS */
  26. #ifdef sequent
  27. extern FILE *popen();
  28. #endif
  29.  
  30. #if defined(SYSV) || defined(SVR4)
  31. #include <string.h>
  32.  
  33. #ifndef index
  34. #define index strchr
  35. #endif
  36.  
  37. #ifndef rindex
  38. #define rindex strrchr
  39. #endif
  40.  
  41. #else  /* defined(SYSV) || defined(SVR4) */
  42. #include <strings.h>
  43. #endif
  44.  
  45. #endif /* VMS */
  46.  
  47. #include "xpm.h"
  48.  
  49. #if defined(SYSV) || defined(SVR4) || defined(VMS)
  50. #define bcopy(source, dest, count) memcpy(dest, source, count)
  51. #define bzero(b, len) memset(b, 0, len)
  52. #endif
  53.  
  54.  
  55. /* the following should help people wanting to use their own functions */
  56. #define XpmMalloc(size) malloc((size))
  57. #define XpmRealloc(ptr, size) realloc((ptr), (size))
  58. #define XpmCalloc(nelem, elsize) calloc((nelem), (elsize))
  59.  
  60.  
  61. typedef struct {
  62.     unsigned int type;
  63.     union {
  64.     FILE *file;
  65.     char **data;
  66.     }     stream;
  67.     char *cptr;
  68.     unsigned int line;
  69.     int CommentLength;
  70.     char Comment[BUFSIZ];
  71.     char *Bcmt, *Ecmt, Bos, Eos;
  72.     int format;            /* 1 if XPM1, 0 otherwise */
  73. }      xpmData;
  74.  
  75. #define XPMARRAY 0
  76. #define XPMFILE  1
  77. #define XPMPIPE  2
  78. #define XPMBUFFER 3
  79.  
  80. typedef unsigned char byte;
  81. typedef int Boolean;
  82.  
  83. #define EOL '\n'
  84. #define TAB '\t'
  85. #define SPC ' '
  86.  
  87. typedef struct {
  88.     char *type;                /* key word */
  89.     char *Bcmt;                /* string beginning comments */
  90.     char *Ecmt;                /* string ending comments */
  91.     char Bos;                /* character beginning strings */
  92.     char Eos;                /* character ending strings */
  93.     char *Strs;                /* strings separator */
  94.     char *Dec;                /* data declaration string */
  95.     char *Boa;                /* string beginning assignment */
  96.     char *Eoa;                /* string ending assignment */
  97. }      xpmDataType;
  98.  
  99. extern xpmDataType xpmDataTypes[];
  100.  
  101. /*
  102.  * rgb values and ascii names (from rgb text file) rgb values,
  103.  * range of 0 -> 65535 color mnemonic of rgb value
  104.  */
  105. typedef struct {
  106.     int r, g, b;
  107.     char *name;
  108. }      xpmRgbName;
  109.  
  110. /* Maximum number of rgb mnemonics allowed in rgb text file. */
  111. #define MAX_RGBNAMES 1024
  112.  
  113. extern char *xpmColorKeys[];
  114.  
  115. #define TRANSPARENT_COLOR "None"    /* this must be a string! */
  116.  
  117. /* number of xpmColorKeys */
  118. #define NKEYS 5
  119.  
  120. /* XPM private routines */
  121.  
  122. FUNC(xpmWriteData, int, (xpmData *mdata, XpmImage *image, char *name,
  123.              XpmInfo *info));
  124.  
  125. FUNC(xpmParseData, int, (xpmData *data, XpmImage *image, XpmInfo *info));
  126.  
  127. FUNC(xpmFreeColorTable, void, (XpmColor *colorTable, int ncolors));
  128.  
  129. FUNC(xpmInitAttributes, void, (XpmAttributes *attributes));
  130.  
  131. FUNC(xpmInitXpmImage, void, (XpmImage *image));
  132.  
  133. FUNC(xpmInitXpmInfo, void, (XpmInfo *info));
  134.  
  135. FUNC(xpmSetInfoMask, void, (XpmInfo *info, XpmAttributes *attributes));
  136. FUNC(xpmSetInfo, void, (XpmInfo *info, XpmAttributes *attributes));
  137. FUNC(xpmSetAttributes, void, (XpmAttributes *attributes, XpmImage *image,
  138.                   XpmInfo *info));
  139.  
  140. FUNC(xpmCreatePixmapFromImage, void, (Display *display, Drawable d,
  141.                       XImage *ximage, Pixmap *pixmap_return));
  142.  
  143. FUNC(xpmCreateImageFromPixmap, void, (Display *display, Pixmap pixmap,
  144.                       XImage **ximage_return,
  145.                       unsigned int *width,
  146.                       unsigned int *height));
  147.  
  148. /* I/O utility */
  149.  
  150. FUNC(xpmNextString, int, (xpmData *mdata));
  151. FUNC(xpmNextUI, int, (xpmData *mdata, unsigned int *ui_return));
  152. FUNC(xpmGetString, int, (xpmData *mdata, char **sptr, unsigned int *l));
  153.  
  154. #define xpmGetC(mdata) \
  155.     ((!mdata->type || mdata->type == XPMBUFFER) ? \
  156.      (*mdata->cptr++) : (getc(mdata->stream.file)))
  157.  
  158. FUNC(xpmNextWord, unsigned int,
  159.      (xpmData *mdata, char *buf, unsigned int buflen));
  160. FUNC(xpmGetCmt, int, (xpmData *mdata, char **cmt));
  161. FUNC(xpmReadFile, int, (char *filename, xpmData *mdata));
  162. FUNC(xpmWriteFile, int, (char *filename, xpmData *mdata));
  163. FUNC(xpmOpenArray, void, (char **data, xpmData *mdata));
  164. FUNC(xpmDataClose, int, (xpmData *mdata));
  165. FUNC(xpmParseHeader, int, (xpmData *mdata));
  166. FUNC(xpmOpenBuffer, void, (char *buffer, xpmData *mdata));
  167.  
  168. /* RGB utility */
  169.  
  170. FUNC(xpmReadRgbNames, int, (char *rgb_fname, xpmRgbName *rgbn));
  171. FUNC(xpmGetRgbName, char *, (xpmRgbName *rgbn, int rgbn_max,
  172.                  int red, int green, int blue));
  173. FUNC(xpmFreeRgbNames, void, (xpmRgbName *rgbn, int rgbn_max));
  174.  
  175. FUNC(xpm_xynormalizeimagebits, void, (register unsigned char *bp,
  176.                       register XImage *img));
  177. FUNC(xpm_znormalizeimagebits, void, (register unsigned char *bp,
  178.                      register XImage *img));
  179.  
  180. /*
  181.  * Macros
  182.  *
  183.  * The XYNORMALIZE macro determines whether XY format data requires
  184.  * normalization and calls a routine to do so if needed. The logic in
  185.  * this module is designed for LSBFirst byte and bit order, so
  186.  * normalization is done as required to present the data in this order.
  187.  *
  188.  * The ZNORMALIZE macro performs byte and nibble order normalization if
  189.  * required for Z format data.
  190.  *
  191.  * The XYINDEX macro computes the index to the starting byte (char) boundary
  192.  * for a bitmap_unit containing a pixel with coordinates x and y for image
  193.  * data in XY format.
  194.  *
  195.  * The ZINDEX* macros compute the index to the starting byte (char) boundary
  196.  * for a pixel with coordinates x and y for image data in ZPixmap format.
  197.  *
  198.  */
  199.  
  200. #define XYNORMALIZE(bp, img) \
  201.     if ((img->byte_order == MSBFirst) || (img->bitmap_bit_order == MSBFirst)) \
  202.     xpm_xynormalizeimagebits((unsigned char *)(bp), img)
  203.  
  204. #define ZNORMALIZE(bp, img) \
  205.     if (img->byte_order == MSBFirst) \
  206.     xpm_znormalizeimagebits((unsigned char *)(bp), img)
  207.  
  208. #define XYINDEX(x, y, img) \
  209.     ((y) * img->bytes_per_line) + \
  210.     (((x) + img->xoffset) / img->bitmap_unit) * (img->bitmap_unit >> 3)
  211.  
  212. #define ZINDEX(x, y, img) ((y) * img->bytes_per_line) + \
  213.     (((x) * img->bits_per_pixel) >> 3)
  214.  
  215. #define ZINDEX32(x, y, img) ((y) * img->bytes_per_line) + ((x) << 2)
  216.  
  217. #define ZINDEX16(x, y, img) ((y) * img->bytes_per_line) + ((x) << 1)
  218.  
  219. #define ZINDEX8(x, y, img) ((y) * img->bytes_per_line) + (x)
  220.  
  221. #define ZINDEX1(x, y, img) ((y) * img->bytes_per_line) + ((x) >> 3)
  222.  
  223. #if __STDC__
  224. #define Const const
  225. #else
  226. #define Const                /**/
  227. #endif
  228.  
  229. /*
  230.  * there are structures and functions related to hastable code
  231.  */
  232.  
  233. typedef struct _xpmHashAtom {
  234.     char *name;
  235.     void *data;
  236. }      *xpmHashAtom;
  237.  
  238. typedef struct {
  239.     int size;
  240.     int limit;
  241.     int used;
  242.     xpmHashAtom *atomTable;
  243. }      xpmHashTable;
  244.  
  245. FUNC(xpmHashTableInit, int, (xpmHashTable *table));
  246. FUNC(xpmHashTableFree, void, (xpmHashTable *table));
  247. FUNC(xpmHashSlot, xpmHashAtom *, (xpmHashTable *table, char *s));
  248. FUNC(xpmHashIntern, int, (xpmHashTable *table, char *tag, void *data));
  249.  
  250. #define HashAtomData(i) ((void *)i)
  251. #define HashColorIndex(slot) ((unsigned int)((*slot)->data))
  252. #define USE_HASHTABLE (cpp > 2 && ncolors > 4)
  253.  
  254. #ifdef NEED_STRDUP
  255. FUNC(strdup, char *, (char *s1));
  256. #endif
  257.  
  258. #endif
  259.